package com.example.controller.user;

import com.example.dto.SoundComDto;
import com.example.result.Result;
import com.example.service.PPTService;
import com.example.utils.AliOssUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.UUID;

@RestController
@RequestMapping
@Slf4j
public class PPTController {

 @Autowired
 private PPTService pptService;
 @Autowired
 private AliOssUtil aliOssUtil;
    @PostMapping("front/courseware/generate-courseware")
    public Result pptToVideo(
            @RequestParam("voice") Long voice,
            @RequestParam("speed") double speed,
            @RequestParam("tone") double tone,
            @RequestParam("rhythm") double rhythm,
            @RequestParam(value = "courseware", required = false) MultipartFile courseware) throws Exception {
        String originalFilename = courseware.getOriginalFilename();
        String extension = originalFilename.substring(originalFilename.lastIndexOf("."));
        String filename = UUID.randomUUID() + extension;
        String filepath = aliOssUtil.upload(courseware.getBytes(), filename);
       log.info("开始下载ppt");
        SoundComDto scd=SoundComDto.builder()
                .id(voice)
                .rate(speed)
                .pitch(tone)
                .build();
       String url =  pptService.pptToVideo(filepath,scd);
        return Result.success(url);

}
    @PostMapping("ppt/test")
    public Result pptToVideoTest() throws Exception {
        SoundComDto scd = SoundComDto.builder().build();

        String url =  pptService.pptToVideo("11",scd);
        return Result.success(url);

    }

}